﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;

namespace WindowsFormsApp1
{
    public class DbHelper
    {
        public static readonly string conString = "server=.;database=Blogs;uid=sa;pwd=20010129szq";
        
        public static int Operate(string cmdString)
        {
            SqlConnection sqlConnection = new SqlConnection(cmdString);
            using (SqlCommand command = new SqlCommand(cmdString, sqlConnection))
            {
                sqlConnection.Open();
                return command.ExecuteNonQuery();
            }
        }
        public static DataTable GetDataTable(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, conString);
            DataTable dataTable = new DataTable();
            sqlConnection.Open();
            sqlDataAdapter.Fill(dataTable);
            return dataTable;
        } 
    }
}
